fix(@angular/build): respect sourceMap configuration in dev server#32941
fix(@angular/build): respect sourceMap configuration in dev server#32941maruthang wants to merge 1 commit intoangular:mainfrom
Conversation
The dev server was ignoring the `sourceMap` configuration from angular.json, always injecting inline source maps into all served files. This affected both CSS (hardcoded `devSourcemap: true`) and JavaScript (prebundle transformer hardcoded `sourcemap: true`), causing 2-3x file size inflation even when source maps were explicitly disabled. The fix passes the normalized `scripts` and `styles` source map settings through to the Vite configuration, so that `css.devSourcemap` and the prebundle transformer respect the user's `sourceMap` setting. Closes angular#31331
There was a problem hiding this comment.
Code Review
This pull request enhances the Vite dev server by implementing granular source map controls, specifically adding support for style source maps and replacing hardcoded values with configuration-driven settings. A review comment identifies that the prebundleTransformer should utilize thirdPartySourcemaps rather than scriptsSourcemaps to ensure that third-party dependency source maps are only generated when explicitly configured.
| // In a development environment the additional scope information does not | ||
| // have a negative effect unlike production where final output size is relevant. | ||
| { sourcemap: true, jit: true, thirdPartySourcemaps }, | ||
| { sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps }, |
There was a problem hiding this comment.
The prebundleTransformer is used specifically for third-party dependencies during the Vite prebundling process. It should therefore respect the thirdPartySourcemaps (which corresponds to the vendor source map setting) rather than scriptsSourcemaps for its internal sourcemap generation toggle.
Using scriptsSourcemaps here means that if a user has "sourceMap": true (which defaults vendor to false in Angular), source maps will still be generated for prebundled third-party packages, which contradicts the configuration and the stated goal of this PR to avoid injecting source maps when disabled.
| { sourcemap: scriptsSourcemaps, jit: true, thirdPartySourcemaps }, | |
| { sourcemap: thirdPartySourcemaps, jit: true, thirdPartySourcemaps }, |
Summary
sourceMapconfiguration fromangular.json, always injecting inline source maps into all served files even when explicitly disabledcss.devSourcemapwas hardcoded totrueinstead of using thestylessource map settingJavaScriptTransformerwas created withsourcemap: truehardcoded, causing Vite's dependency prebundling to always generate source maps for third-party packagesscriptsandstylessource map settings through to the Vite configurationCloses #31331
Test plan
ng servewith"sourceMap": falsein angular.json and verify no inline source maps in served JS/CSS filesng servewith default config and verify source maps still workng servewith granular config{"scripts": false, "styles": true}and verify only CSS has source maps